/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package client;
import java.io.Serializable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import session.*;
import entity.*;
/**
 *
 * @author Admin
 */
public class clientBean implements Serializable{
    private static final long serialVersionUID = 1L;
  private Context jndiContext;
  	private nowaRemote dao;
    private Users user;
    private Accounts account;

    private String nazwa="";
        public clientBean() {
    }
    public void open(){
        try{
        System.out.println("Start Klienta...");
			jndiContext = getInitialContext();
                        System.out.println("Start Klienta..1");
			Object ref = jndiContext.lookup("nowa/nowaBean/remote");
			System.out.println("Start Klienta..2");
                      dao = (nowaRemote)
				PortableRemoteObject.narrow(ref,nowaRemote.class);
        }
        catch(Exception e){
System.out.println(e.toString());
    }
        }

    public Users getUser(){
        return this.user;
    }
    public void setUser(Users user){
        this.user=user;
    }
   public Accounts getAccount(){
        return this.account;
    }
    public void setAccount(Accounts account){
        this.account=account;
    }
public String getUname(){
    return user.getUName();
}

public String getUpass(){
    return user.getUPass();
}

public String getUemail(){
    return user.getUEmail();
}

public String getId(){
    return account.getId();
}

public java.math.BigDecimal getSaldo(){
    return account.getSaldo();
}

public String getAccUname(){
    return account.getUName().getUName();
}

public String getNazwa(){
    return nazwa;

}
public void setNazwa(String nazwa){
    this.nazwa=nazwa;
}
private String login,pass;
public void setLogin(String l){
    login=l;
}
public void setPass(String p){
    pass=p;
}
public String getLogin(){
   return login;
}
public String getPass(){
   return pass;
}
public void loguj(){
    try{
    Users u;
   u = dao.findUser(login);
   if(u.getUPass().equals(pass)){
       nazwa=pass;
   }else nazwa="pass_error";
    }catch(Exception e){
        nazwa="pass_error";
    }
    }

    public static Context getInitialContext()
			throws NamingException {

		Properties p = new Properties( );
		p.put(Context.INITIAL_CONTEXT_FACTORY,
			"org.jnp.interfaces.NamingContextFactory");
		p.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
		p.put(Context.PROVIDER_URL,"jnp://localhost:1099");
		return new InitialContext(p);
	}
}
